package com.zhang.handler;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.Date;


/**
 * @author ZhangJunqi
 * @Date 2022/3/27 -10:59
 */
@Slf4j
@Component
public class MyMetaObjectHandler implements MetaObjectHandler {

    @Override
    public void insertFill(MetaObject metaObject) {
        log.info ("insert fill");
        this.setFieldValByName ("createTime",new Date (),metaObject);
        this.setFieldValByName ("updateTime",new Date (),metaObject);
//        this.fillStrategy(metaObject, "createTime", LocalDateTime.now());//LocalDateTime类型
//        this.fillStrategy(metaObject, "updateTime", LocalDateTime.now());
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        log.info ("update fill");
        this.setFieldValByName ("updateTime",new Date (),metaObject);
//        this.fillStrategy(metaObject, "updateTime", LocalDateTime.now());
    }
}
